package scau.erps.view.dashboard;

import java.util.List;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

import scau.erps.app.Erps;
import scau.erps.entity.Balancesheet;
import scau.erps.service.BalancesheetService;
import scau.erps.service.impl.BalancesheetServiceImpl;

/**
 * 企业总资产折线图
 * @author DCJ
 */
public class TotalAssetChart{	
	/**
	 * 得到图片
	 * @return
	 */
	public static JFreeChart getChart(){
		JFreeChart chart = createChart(createDataset());
		return chart;
	}
	/**
	 * 数据
	 */
	public static DefaultCategoryDataset createDataset() {
		DefaultCategoryDataset linedataset = new DefaultCategoryDataset();
		String series = "总资产";


		BalancesheetService balancesheetService=Erps.getIocInstance().get(BalancesheetServiceImpl.class);	
		List<Balancesheet> list=balancesheetService.getBalancesheetByTeamid(Erps.getCurrentTeam().getId());
		
		
        for (Balancesheet balancesheet:list){
        	String year=balancesheet.getYear();
        	if(year.equals("Y8")) continue;
        	linedataset.addValue(balancesheet.getTotalAsset(), series, year);
        }
		

		return linedataset;
	}
	/**
	 * 绘制折线
	 */
	public static JFreeChart createChart(DefaultCategoryDataset linedataset) {
		  //createLineChart 参数依次为：标题，横坐标标题，纵坐标标题，数据，方向，图例，工具，超链接
		  JFreeChart chart = ChartFactory.createLineChart("企业总资产", "年份", "价值(M)", linedataset, PlotOrientation.VERTICAL, true, true, false);
		  return chart;
		 }
	}
